package com.fast.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fast.domain.SysUser;
import com.fast.service.UserService;

@Controller
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping("/list")
	public List<SysUser> index() {
		return userService.getAll();
	}

	@RequestMapping("/test")
	@ResponseBody
	public String test() throws Exception {
		try {
			List<String> users = new ArrayList();
			users.add("tonny");
			for (String item : users) {
				users.remove(item);
			}
		} catch (Exception e) {
			throw new Exception("ex test");
		}
		return "login";
	}

	@RequestMapping("/test2")
	@ResponseBody
	public String test2() throws org.apache.shiro.authz.UnauthorizedException {
		try {
			List<String> users = new ArrayList();
			users.add("tonny");
			for (String item : users) {
				users.remove(item);
			}
		} catch (Exception e) {
			throw new org.apache.shiro.authz.UnauthorizedException("ex test");
		}
		return "login";
	}

	@RequestMapping("/add")
	public String add() {
		return "add";
	}

	@RequestMapping("/test/**")
	public ModelAndView test1(ModelAndView view) {
		view.setViewName("test");
		view.addObject("attr", "UserController -> /test/**");
		return view;
	}
}
